package cn.edu.ujn.boot.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.ujn.boot.dao.UserMapper;
import cn.edu.ujn.boot.po.User;
import cn.edu.ujn.boot.service.IUserService;

@Service("UserService")
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User login(User user) {
		// TODO 用户登录实现
		if(user.getClass() == null)
			throw new RuntimeException("");
		if (user.getUser_code().trim()=="") {
			throw new RuntimeException("账号不可为空!!!");
		}	
		else if (user.getUser_password().trim()=="")
			throw new RuntimeException("密码不可为空!!!");
		else {
		User editUser = new User(); 
		editUser= userMapper.getUserByUsername(user.getUser_code());
		
		if (editUser == null) 
			throw new RuntimeException("账号不存在!!!");
		else
		if (editUser.getUser_password().equals(user.getUser_password())) {
			return editUser;
		}
		else {
			throw new RuntimeException("密码错误!!!");
		}
		}
	}

}
